#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@File    :   main_span.py    
@Contact :   raogx.vip@hotmail.com
@License :   (C)Copyright 2020

@Modify Time      @Author    @Version    @Desciption
------------      -------    --------    -----------
2021-05-13 18:49   WandongShi      1.0         None
'''
 
import torch
import argparse

from args import train_argparser, eval_argparser, predict_argparser
from models import input_reader
from config_reader import process_configs
from models.span_trainer import OpinionMiner

def _train():
    arg_parser = train_argparser()
    process_configs(target=__train, arg_parser=arg_parser)

def __train(run_args):
    trainer = OpinionMiner(run_args)
    trainer.train(train_path=run_args.train_path, valid_path=run_args.valid_path,
                  types_path=run_args.types_path, input_reader_cls=input_reader.JsonInputReader)

def _eval():
    arg_parser = eval_argparser()
    process_configs(target=__eval, arg_parser=arg_parser)


def __eval(run_args):
    trainer = OpinionMiner(run_args)
    trainer.eval(dataset_path=run_args.dataset_path, types_path=run_args.types_path,
                 input_reader_cls=input_reader.JsonInputReader)

if __name__ == "__main__":
    _train()
